package week10;

/**
 * @author The setting sun
 * @version 1.0
 * @title: pay
 * @description: TODO
 * @date 2021/11/10 9:06
 */
public class Work1 {
    public static void main(String[] args) {
        MyThread mt = new MyThread();

        Thread t1 = new Thread(mt, "窗口1");
        Thread t2 = new Thread(mt, "窗口2");
        Thread t3 = new Thread(mt, "窗口3");
        Thread t4 = new Thread(mt, "窗口4");

        t1.start();
        t2.start();
        t3.start();
        t4.start();

    }
}

class MyThread implements Runnable {
    int p = 100;

    @Override
    public void run() {
        while (true) {
            synchronized (MyThread.class) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                if (p > 0) {
                    System.out.println(Thread.currentThread().getName() + "：" + p + "号票售出");
                    p--;
                } else {
                    return;
                }
            }
        }
    }
}
